package com.jiazixuan.stock.face.impl;

import com.jiazixuan.stock.constant.StockConstant;
import com.jiazixuan.stock.face.StockCacheFace;
import com.jiazixuan.stock.mapper.StockBusinessMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

@Component
@CacheConfig(cacheNames = StockConstant.STOCK)
public class StockCacheFaceImpl implements StockCacheFace {

    @Autowired
    private StockBusinessMapper stockBusinessMapper;

    @Cacheable(key = "'stockCodes'")
    @Override
    public List<String> getAllStockCodeWithPredix() {
        //获取股票id
        List<String> stockIds = stockBusinessMapper.getStockIds();
        //计算出符合规范的id
        List<String> allCodes = stockIds.stream().map(code -> code.startsWith("6") ? "sh" + code : "sz" + code).collect(Collectors.toList());
        return allCodes;
    }
}
